package sample.templates;

import java.util.Enumeration;
import java.util.Vector;

class Tbin extends Vector {
	Class binType;

	Tbin(Class binType) {
		this.binType = binType;
	}

	boolean grab(Trash T) {
		if (T.getClass().equals(binType)) {
			this.addElement(T);
			return true;
		}
		return false;
	}

}

class TbinList extends Vector {
	boolean sort(Trash T) {
		Enumeration e = elements();
		while (e.hasMoreElements()) {
			Tbin bin = (Tbin) e.nextElement();
			if (bin.grab(T))
				return true;
		}
		return false;
	}

	public void sortBin(Tbin bin) {
		Enumeration e = bin.elements();
		while (e.hasMoreElements()) {
			if (!sort((Trash) e.nextElement())) {
				System.out.println("Bin not found");
			}
		}
	}
}

public class Recycle {
	static Tbin bin = new Tbin(Trash.class);

	public static void main(String[] args) throws Exception {
		parseTrash.fillBin("C:\\Trash.dat", bin);// filename is "Trash.dat"
		TbinList trashBins = new TbinList();
		trashBins.addElement(new Tbin(Papers.class));
		trashBins.addElement(new Tbin(Aluminums.class));
		trashBins.addElement(new Tbin(Glasses.class));
		trashBins.addElement(new Tbin(Cardboards.class));

		trashBins.sortBin(bin);

		Enumeration e = trashBins.elements();
		while (e.hasMoreElements()) {
			Tbin b = (Tbin) e.nextElement();
			Trash.sumValue(b);
		}

		Trash.sumValue(bin);

	}

}
